#ifndef BULLET_H
#define BULLET_H

#include <QPainter>
#include <QPainterPath>
#include "collision.h"
#include "movingobject.h"
#include "map.h"

class Map;

class Bullet : public MovingObject
{
    Q_OBJECT
public:
    enum { Type = UserType + 2 };
    int type() const
    {
        // Enable the use of qgraphicsitem_cast with this item.
        return Type;
    }
    QRectF boundingRect() const;
    QPainterPath shape () const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                        QWidget *widget);

    void moveBullet();
    Bullet(QPointF start_pos, qreal angle, Player* owner);
    bool isFirstUpdate;
    Map* map();
    void checkCollisions();
private:
    Player* owner;
    qreal velocity;
    qreal distanceTravelled;
    bool isHit;
    qreal angle;
    qreal bulletLen;
    qreal actualBulletLen;
    qreal halfLen;
    QPointF start_pos;
    QPainterPath bulletShape;
    QRectF bulletRect;
    QLineF shapeLine;
    QLineF drawLine;

signals:
    void hitPolygon();
    void hitPlayer(Player*,Player*);
};

#endif // BULLET_H
